#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSerialPortInfo>
#include <QDebug>
#include <QMutex>
#include "Qss.h"
#include "libmodbus/modbus.h"
#include <math.h>
#include <QTimer>
#include <QFileDialog>
#include "global.h"
#include <subform.h>

#if defined(_MSC_VER) && (_MSC_VER >= 1600)
# pragma execution_character_set("utf-8")
#endif




MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , mStart(false)
    , mConfig(nullptr) {
    ui->setupUi(this);
    auto list3 = QSerialPortInfo::availablePorts();
    for(int i=0;i<list3.size();i++){
        qDebug()<<list3[i].portName();//
        ui->comboBox_2->addItem(list3[i].portName());
    }
    ui->comboBox->addItem("2400");
    ui->comboBox->addItem("4800");
    ui->comboBox->addItem("9600");
    ui->comboBox->addItem("57600");
    ui->comboBox->addItem("115200");


}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::init_charts()
{
}


void MainWindow::on_pushButton_2_clicked()
{

}

void MainWindow::on_pushButton_clicked()
{
}


void MainWindow::on_pushButton_3_clicked()
{
  if(nullptr == gAsyncData){
      gAsyncData = new ASyncReadData(this);
      connect(gAsyncData,&QSSASyncProcess::Done,[&](){
          qDebug()<<"done";
      });
      qDebug()<<"hello world";
      gAsyncData->Start(nullptr);

  }
    if(this->mForms.contains(ui->lineEdit_2->text())){
        QMessageBox::warning(this,"�����Ѿ���","�����Ѿ���");
        return;
    }
    SubForm *p1 = new SubForm(ui->comboBox_2->currentText(),
                              ui->comboBox->currentText().toInt(),
                              ui->lineEdit_2->text().toInt(),
                              ui->lineEdit_3->text().toInt());
    qDebug()<<ui->lineEdit_2->text();
    ui->tabWidget->addTab((QWidget*)p1,"address:" + ui->lineEdit_2->text());
    this->mForms[ui->lineEdit_2->text()] = p1;




}

